package CapaDatos;

import java.util.GregorianCalendar;

public class Hora extends GregorianCalendar
{
    public Hora ()
    {
        super();
    }

    public Hora (String horaCadena)
    {
        String[] hora = horaCadena.split(":");
        this.clear();
        this.set
                (
                    2000, 0, 1,
                    Integer.valueOf(hora[0]),
                    Integer.valueOf(hora[1])
                );
        this.complete();
    }

    // <editor-fold defaultstate="collapsed" desc="toString">
    @Override public String toString() {
        if (!this.isSet(Hora.HOUR_OF_DAY))
            return null;

        String hora[] =
        {
            String.valueOf(this.get(Hora.HOUR_OF_DAY)),
            String.valueOf(this.get(Hora.MINUTE))
        };

        if (hora[0].length() < 2)
            hora[0] = "0" + hora[0];
        if (hora[1].length() < 2)
            hora[1] = "0" + hora[1];

        return (hora[0] + ":" + hora[1]);
    }
    // </editor-fold>
}
